<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;


/**
 * App\Models\UserTree
 *
 * @property int $id 主键
 * @property int $uid 用户ID
 * @property int $treeid 树种ID
 * @property int $quantity
 * @property int $bubbles 气泡总数
 * @property float $bubbles_released 已释放气泡数
 * @property int $days 释放天数
 * @property int $created_at 种树时间
 * @property int $updated_at 更新时间
 * @property-read \App\Models\Trees $tree
 * @property-read \App\Models\User $user
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserTree whereBubbles($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserTree whereBubblesReleased($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserTree whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserTree whereDays($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserTree whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserTree whereQuantity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserTree whereTreeid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserTree whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserTree whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property float $bubbles_picked 已拾取气泡
 * @property float $energy 能量
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserTree whereBubblesPicked($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserTree whereEnergy($value)
 * @property int $released_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserTree whereReleasedAt($value)
 */
class UserTree extends Model
{
    protected $table = 'user_tree';
    protected $primaryKey = 'id';
    protected $guarded = ['id'];

    public $timestamps = false;

    public static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
        static::creating(function ($model){
            if (!$model->created_at) $model->created_at = time();
        });

        static::updating(function ($model){
            if ($model->updated_at) $model->updated_at = time();
        });
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'uid', 'uid');
    }

    public function tree()
    {
        return $this->belongsTo(Trees::class, 'treeid', 'treeid');
    }
}
